package com.wlyuan.open.scanner.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.dto.top.ExtensionGoodsDTO;
import com.wlyuan.open.dto.top.OpenTopExtensionOrderSyncDTO;
import com.wlyuan.open.scanner.domain.extension.Extension;
import com.wlyuan.open.scanner.domain.order.OrderGoods;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ScannerTopExtensionAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {MappingInvalid.class, MappingIds.class})
    public interface Assembler {

        /**
         * 转换
         *
         * @param source
         * @return
         */
        @Mappings({
                @Mapping(source = "closed", target = "off"),
        })
        OpenTopExtensionOrderSyncDTO assemble(Extension source);

        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<OpenTopExtensionOrderSyncDTO> assemble(List<Extension> source);

        @Mappings({
                @Mapping(source = "code", target = "itemNo"),
                @Mapping(source = "goodsName", target = "name"),
                @Mapping(source = "materialCode", target = "barcode"),
                @Mapping(source = "goodsName", target = "chineseName"),

                @Mapping(source = "notAxUnitPrice", target = "noTaxPrice"),
                @Mapping(source = "notAxPrice", target = "taxPrice"),
                @Mapping(source = "totalPrice", target = "taxAmount"),
                @Mapping(source = "taxPrice", target = "noTaxAmount"),

                @Mapping(source = "kbetrWs", target = "itemDiscountNoTax"),
                @Mapping(source = "mwsbpZk", target = "itemDiscountTax"),
                @Mapping(source = "mwsbp", target = "itemTax"),
                @Mapping(source = "kbetr", target = "itemDiscount"),
                @Mapping(source = "extendDoc", target = "purchaseUnit"),

                @Mapping(source = "createAt", target = "createBy"),
                @Mapping(source = "updateAt", target = "updateBy"),
                @Mapping(source = "createTime", target = "createAt"),
                @Mapping(source = "updateTime", target = "updateAt"),


        })
        ExtensionGoodsDTO assembler(OrderGoods source);

        List<ExtensionGoodsDTO> assembler(List<OrderGoods> source);

    }

    public static List<OpenTopExtensionOrderSyncDTO> assemble(List<Extension> creation) {
        return ASSEMBLER.assemble(creation);
    }

    public static OpenTopExtensionOrderSyncDTO assemble(Extension source) {
        return ASSEMBLER.assemble(source);
    }

}
